/**
 * \class AddExp.cpp
 *
 *  Created on: 31 mar 2011
 *      Author: ytc0039
 */

#include "AddExp.h"
#include <Interfaces/IExpVisitor.h>
#include <stdio.h>
#include <AbsSyn/IntExp.h>
#include <boost/bind.hpp>






AddExp::AddExp(const IExp *lhs,const IExp *rhs):
m_lhs(lhs->clone()),
m_rhs(rhs->clone())
{
	//onCreate = boost::bind(&AddExp::clone,this);
}

AddExp::~AddExp() {
	delete m_lhs;
	m_lhs = NULL;
	delete m_rhs;
	m_rhs = NULL;


}

void AddExp::accept(IExpVisitor *v) {
	v->VisitAddExp(this);
}


AddExp* AddExp::clone() const
{
	return (new AddExp(m_lhs,m_rhs));
}

AbsSyn::IExpPtr AddExp::generateAddExp(GenExp& genObj)
{
	AbsSyn::IExpPtr arg1 = genObj.genExp(GenExp::RANDOM);
	AbsSyn::IExpPtr arg2 = genObj.genExp(GenExp::RANDOM);
	assert(arg1 != NULL);
	assert(arg2 != NULL);
	AbsSyn::IExpPtr ptr( new AddExp(arg1.get(),arg2.get()) );
	return ptr;
}

std::string AddExp::toString()const
{
	std::string ret;
	assert(m_lhs != NULL );
	assert(m_rhs != NULL);

	if(m_lhs && m_rhs)
		ret = "(" + m_lhs->toString() + " + " + m_rhs->toString() + ")";

	return ret;
}
